<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Methods</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
  <h1>Methods</h1>
  <hr>
  <div id="app">
    <p>{{count}}</p>
    <p><button @click="add(2)">add</button></p>
    <p><btn @click.native="add(2)"></btn></p>
  </div>
  <button onclick="app.add(3)">外部add</button>
  <script type="text/javascript">
  var btn={
    template:`<button>组件ADD</button>`
  }
  var app = new Vue({
    el:'#app',
    data:{
      count:0
    },
    components:{
      'btn':btn
    },
    methods:{
      add:function(num){
        if(num != ''){
          this.count += num;
        }
        else{
          this.count++;
        }
      }
    }
  })
  </script>
</body>
</html>